#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
using namespace std;


struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};

class Solution {
public:
    vector<vector<int> > Print(TreeNode* pRoot)
    {
        TreeNode* head = pRoot;
        vector<vector<int> > vv;

        if (!pRoot) return vv;
        queue<TreeNode*> q;
        q.push(head);
        TreeNode* p;
        while (!q.empty())
        {
            vector<int> v;
            int n = q.size();
            while (n--)
            {
                p = q.front();
                q.pop();
                v.push_back(p->val);
                if (p->left) q.push(p->left);
                if (p->right) q.push(p->right);
            }
            vv.push_back(v);
        }
        reverse(vv.begin(),vv.end());
        return vv;
    }

};
//void main()
//{
//    Solution A;
//}